From 3a3d5d6a90d4bab38a7675daffec017d8e9c73c9 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 7 Nov 2014 12:59:44 -0800 Subject: [PATCH] Another fix for cross-compiled build scripts Previously the host/target requirement for packages was not correctly calculated as dependency edges to build dependencies weren't traversed by accident. --- src/cargo/ops/cargo_rustc/context.rs | 14 ++++++++-- tests/test_cargo_cross_compile.rs | 41 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 89e526308..600d65449 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -149,10 +149,10 @@ impl<'a, 'b: 'a> Context<'a, 'b> { fn build_requirements(&mut self, pkg: &'a Package, target: &'a Target, req: PlatformRequirement, - visiting: &mut HashSet<&'a PackageId>) { - if !visiting.insert(pkg.get_package_id()) { return } + visiting: &mut HashSet<(&'a PackageId, &'a str)>) { let key = (pkg.get_package_id(), target.get_name()); + if !visiting.insert(key) { return } let req = if target.get_profile().is_for_host() {PlatformPlugin} else {req}; match self.requirements.entry(key) { Occupied(mut entry) => { *entry.get_mut() = entry.get().combine(req); } @@ -163,7 +163,15 @@ impl<'a, 'b: 'a> Context<'a, 'b> { self.build_requirements(pkg, dep, req, visiting); } - visiting.remove(&pkg.get_package_id()); + match pkg.get_targets().iter().find(|t| t.get_profile().is_custom_build()) { + Some(custom_build) => { + self.build_requirements(pkg, custom_build, PlatformPlugin, + visiting); + } + None => {} + } + + visiting.remove(&key); } pub fn get_requirement(&self, pkg: &'a Package, diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index 71aea949b..c8c79a112 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -598,3 +598,44 @@ test!(build_script_needed_for_host_and_target { ", compiling = COMPILING, running = RUNNING, target = target, host = host, dir = p.root().display(), sep = path::SEP).as_slice())); }) + +test!(build_deps_for_the_right_arch { + if disabled() { return } + + let p = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.0" + authors = [] + + [dependencies.d2] + path = "d2" + "#) + .file("src/main.rs", "extern crate d2; fn main() {}") + .file("d1/Cargo.toml", r#" + [package] + name = "d1" + version = "0.0.0" + authors = [] + "#) + .file("d1/src/lib.rs", " + pub fn d1() {} + ") + .file("d2/Cargo.toml", r#" + [package] + name = "d2" + version = "0.0.0" + authors = [] + build = "build.rs" + + [build-dependencies.d1] + path = "../d1" + "#) + .file("d2/build.rs", "extern crate d1; fn main() {}") + .file("d2/src/lib.rs", ""); + + let target = alternate(); + assert_that(p.cargo_process("build").arg("--target").arg(&target).arg("-v"), + execs().with_status(0)); +}) -- 2.30.2